//
//  BaseTabBarController.m
//  XinYiGou
//
//  Created by Angel_Yan on 2017/3/15.
//  Copyright © 2017年 Angel_Yan. All rights reserved.
//

#import "BaseTabBarController.h"


#pragma mark - BaseTabBarItem
@implementation BaseTabBarItem

@end



#pragma mark - BaseTabBar

@implementation BaseTabBar

@end



#pragma mark - BaseTabBarController

@interface BaseTabBarController () <UITabBarControllerDelegate>

@property (nonatomic , retain) NSMutableArray *mArrNavCtrl;

@end

@implementation BaseTabBarController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
	[self.navigationController setNavigationBarHidden:YES animated:YES];
}


- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];

}

//- (void)viewDidLoad {
//    [super viewDidLoad];
//    // Do any additional setup after loading the view.
//
//    [self setupInterFace];
//
//
//    self.loginVC = [[LLVCLogin alloc] initWithNibName:NSStringFromClass([LLVCLogin class]) bundle:[NSBundle mainBundle]] ;
//    self.loginVC.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
//    [self.view addSubview:self.loginVC.view];
//    if(![[NSUserDefaults standardUserDefaults] boolForKey:@"isLogin"])
//    {
//        [self.view bringSubviewToFront:self.loginVC.view];
//
//
//    }else{
//        [self connentRC];
//        [self.view sendSubviewToBack:self.loginVC.view];
//        self.loginVC.view.hidden = YES;
//        self.loginVC.view.alpha = 0.5;
//
//        [LLModelUserInfo queryWithOwner:nil finish:^(NSArray *list) {
//            LLModelUserInfo *userInfo = [list firstObject];
//            if (!userInfo) {
//                return ;
//            }
//            NSSet * set = [NSSet setWithObject:userInfo.uesrId];
//            [JPUSHService setTags:set completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
//                if (iResCode!=0) {
////                    [CustomMBHUD showErrorWithStatus:@"设置推送tag错误"];
//                }
//            } seq:1];
//        }];
//    }
//    addNOTIbserver(@selector(loginSucess), Notice_LoginSuccess);
//    addNOTIbserver(@selector(loginOut), Notice_LoginOut);
//
//}


//- (void)loginSucess {
//    [self connentRC];
//    WORK_MAIN(^{
//
//        //设置推送标签
//        [LLModelUserInfo queryWithOwner:nil finish:^(NSArray *list) {
//            LLModelUserInfo *userInfo = [list firstObject];
//            [[NSUserDefaults standardUserDefaults] setObject:userInfo.uesrId forKey:@"userId"];
//
//            NSSet * set = [NSSet setWithObject:userInfo.uesrId];
//            [JPUSHService setTags:set completion:^(NSInteger iResCode, NSSet *iTags, NSInteger seq) {
//                if (iResCode!=0) {
////                    [CustomMBHUD showErrorWithStatus:@"设置推送tag错误"];
//                }
//            } seq:1];
//        }];
//
//        [UIView animateWithDuration:0.3 animations:^{
//            self.loginVC.view.alpha = 0.5;
//            [self.loginVC.view setTransform:CGAffineTransformScale(self.loginVC.view.transform, 1.5, 1.5)];
//        } completion:^(BOOL finished) {
//            self.loginVC.view.hidden = YES;
//            [self.view sendSubviewToBack:self.loginVC.view];
//        }];
//    });
//
//}


//- (void)loginOut {
//
//    [LLModelUserInfo queryWithOwner:nil finish:^(NSArray *list) {
//        LLModelUserInfo *userInfo = [list firstObject];
//
//        //退出
//        NSMutableDictionary *mDicPar = [[NSMutableDictionary alloc] init];
//        mDicPar[@"userId"] = userInfo.uesrId;
//
//        [AFFManger postDataWithAPI:@"/user/exitLogin" andArrayParam:nil andDictParam:mDicPar dataModel:nil isShowLoading:YES requestSuccessed:^(NSString *message, id responseObject) {
//            //        if (!isAppStore) {
//            // 测试服更换成测试的 token
//            NSMutableDictionary *mDicPar = [[NSMutableDictionary alloc] init];
//            mDicPar[@"userId"] = userInfo.uesrId;
//            mDicPar[@"appKey"] = KRongYun_Key; //开发 k51hidwqkn7lb 生产 tdrvipkstqjf5
//            mDicPar[@"appSecret"] = KRongYun_AppSecrect; //开发 ugfWX3b1SUa 生产 0D2ImtdLicm
//            [AFFManger postDataWithAPI:@"/user/refreshToken" andArrayParam:nil andDictParam:mDicPar dataModel:NSStringFromClass([LLModelUserInfo class]) isShowLoading:YES requestSuccessed:^(NSString *message, id responseObject) {
//                //                [CustomMBHUD showErrorWithStatus:@"修改成功"];
//            } requestFailure:^(NSInteger errorCode, NSString *errorMessage) {
//                [CustomMBHUD showErrorWithStatus:errorMessage];
//            }];
//            //        }
//            WORK_MAIN(^{
//                [LLModelUserInfo clearWithOwner:nil];
//                //记得清空账号密码哈
//                [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isLogin"];
//                [[RCIM sharedRCIM] logout];
//                self.selectedIndex = 0;
//                [self.view bringSubviewToFront:self.loginVC.view];
//                self.loginVC.view.hidden = NO;
//                self.loginVC.view.alpha = 1;
//
//                [UIView animateWithDuration:0.3 animations:^{
//                    self.loginVC.view.transform = CGAffineTransformIdentity;
//                    self.loginVC.view.alpha = 1;
//                } completion:^(BOOL finished) {
//
//                }];
//            });
//        } requestFailure:^(NSInteger errorCode, NSString *errorMessage) {
//            [CustomMBHUD showErrorWithStatus:errorMessage];
//        }];
//
//    }];
//}



- (void)dealloc
{
	removeNOTIbserverAll;
}

//- (void)setupInterFace {
//    self.delegate = self;
//    NSArray *arrViewController = @[@{@"title": @"首页",
//                                     @"imgNor":@"icon_home_page_def",
//                                     @"imgSel":@"icon_home_page_sel",
//                                     @"clssName":NSStringFromClass([LLVCMain class]),
//                                     @"isXib":@"0",
//                                     },
//                                   @{@"title":@"我的",
//                                     @"imgNor":@"icon_home_my_def",
//                                     @"imgSel":@"icon_home_my_sel",
//                                     @"clssName":NSStringFromClass([LLVCOwn class]),
//                                    @"isXib":@"1"}
//                                   ];
//
//    self.mArrNavCtrl = [[NSMutableArray alloc] init];
//    for (int i = 0; i < arrViewController.count; i ++) {
//        NSDictionary *dic = arrViewController[i];
//        NSString *className = dic[@"clssName"];
//        UIViewController *viewCtrl;
//        if ([dic[@"isXib"]isEqualToString:@"1"]) {
//            viewCtrl = [[NSClassFromString(className) alloc] initWithNibName:className bundle:[NSBundle mainBundle]];
//        }else{
//            viewCtrl = [[NSClassFromString(className) alloc] init];
//        }
//
//        AFFNavigationController *navTabbar = [[AFFNavigationController alloc] initWithNavigationBarClass:[AFFNavbar class] toolbarClass:nil];        // 这里不能写 initWithRootViewController ,写了之后回走 pushVC 方法。而在那个方法中写了 viewController.hidesBottomBarWhenPushed = YES; 则在切换 tabbar 时候 tabbar 会隐藏;
//        [navTabbar setStatusBarBgColor:kSetting.color_Bg_Nav];
//        navTabbar.viewControllers = @[viewCtrl];
//
//        UIImage *norImg =  [[UIImage imageNamed:dic[@"imgNor"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//        UIImage *selImg =  [[UIImage imageNamed:dic[@"imgSel"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//        BaseTabBarItem *tabItem = [[BaseTabBarItem alloc] initWithTitle:dic[@"title"] image:norImg selectedImage:selImg];
//        [tabItem setTitleTextAttributes:@{NSForegroundColorAttributeName:RGB(153, 153, 153)} forState:UIControlStateNormal];
//        [tabItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithARGBString:@"#1a7ffe"]} forState:UIControlStateSelected];
//        navTabbar.tabBarItem = tabItem;
//        [self.mArrNavCtrl addObject:navTabbar];
//    }
//    self.viewControllers = self.mArrNavCtrl;
//
//    // 设置shadowImage需要设置BackgroundImage ，
//    [self.tabBar setBackgroundImage:[UIImage creatImageWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.tabBar.frame), CGRectGetHeight(self.tabBar.frame)) Color:kSetting.color_ffffff]];
//    [self.tabBar setShadowImage:[UIImage creatImageWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.tabBar.frame), 0.5) Color:[UIColor clearColor]]];
//
//    // 自己添加的顶部线条
//    UILabel *labLine = [CommonMethods addLineLabelWithFrame:CGRectMake(0, -0.5, CGRectGetWidth(self.tabBar.frame), 0.5) color:[UIColor colorWithARGBString:@"#E5E5E5"] alpha:0.5];
//    [self.tabBar addSubview:labLine];
////    [self.tabBar sendSubviewToBack:labLine];
//}


#pragma mark - Noti


#pragma mark - 获取个人信息成功


- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    return YES;
}


- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {


}



- (BOOL)shouldAutorotate
{
    NSLog(@"self.selectedViewController %@" , self.selectedViewController);
    return [self.selectedViewController shouldAutorotate];
}

//- (UIInterfaceOrientationMask)supportedInterfaceOrientations
//{
//    return [self.selectedViewController supportedInterfaceOrientations];
//}
//
//- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
//{
//    return [self.selectedViewController preferredInterfaceOrientationForPresentation];
//}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
